home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FUZZY.ZIP / FUZZY.PRO < prev    next >
Text File  |  1988-02-03  |  3KB  |  100 lines

  1.  
  2. database
  3.   truth(real)
  4.   thresh(real)
  5.   
  6. predicates
  7.   init_fuzzy  fuzzy(real)  threshold(real)
  8.   f_OR  f_AND  p_OR  p_AND  f_NOT
  9.  
  10.   fuzzy_max(real, real, real)
  11.   fuzzy_min(real, real, real)
  12.  
  13. clauses
  14.  
  15.   /* Init_fuzzy must be called before any fuzzy operators or
  16.      predicates are used.  It sets the initial search threshold
  17.      to which fuzzy truth values are compared.                */
  18.  
  19.   init_fuzzy :- asserta(thresh(0.01)).
  20.  
  21.  
  22.   /* Fuzzy is used to specify a particular fuzzy truth value,
  23.      or to retrieve the current truth value.                  */
  24.   
  25.   fuzzy(Truth) :- bound(Truth), asserta(truth(Truth)),
  26.                   retract(thresh(Thresh)),
  27.                   asserta(thresh(Thresh)), !, Truth >= Thresh.
  28.                   
  29.   fuzzy(Truth) :- retract(truth(Truth)),
  30.                   asserta(truth(Truth)), !.
  31.  
  32.  
  33.   /*  Threshold sets or retrieves the search threshold used by
  34.       the Fuzzy Logic operations.  If a call to FUZZY or the
  35.       result of a Fuzzy Logic operator results in a truth value
  36.       less than the threshold, then the predicate or operator
  37.       will fail.                                              */
  38.  
  39.   threshold(Truth) :- bound(Truth), retract(thresh(_)),
  40.                       asserta(thresh(Truth)),
  41.                       retract(truth(Current)),
  42.                       asserta(truth(Current)), !,
  43.                       Current >= Truth.
  44.                       
  45.   threshold(Truth) :- retract(thresh(Truth)),
  46.                       asserta(thresh(Truth)), !.
  47.  
  48.  
  49.   /*  Fuzzy logic contains five basic operators:  fuzzy-AND,
  50.       fuzzy-OR, probability-AND, probability-OR, and NOT.  In
  51.       this Turbo Prolog implementation, these are represented
  52.       by f-AND, f-OR, p-AND, p-OR, and f-NOT respectively.
  53.       "f-NOT" is used to aviod conflicting with the Turbo
  54.       Prolog predicate "NOT."
  55.       
  56.       Since Turbo Prolog does not support true operator
  57.       definition, the Fuzzy Logic operators are used
  58.       syntactically as predicates, in the order specified by
  59.       Reverse Polish Notation (RPN).  For example, the clause
  60.       
  61.         woof :- fuzzy(0.6), fuzzy(0.7), p-AND, fuzzy(0.4), p-OR.
  62.    
  63.       represents the Fuzzy Logic expression
  64.       
  65.         (0.6 p-AND 0.7) p-OR 0.4
  66.       
  67.       Note that only predicates which use Fuzzy Logic will
  68.       generate fuzzy truth value operands.  Other predicates,
  69.       including those built in to Turbo Prolog, do not generate
  70.       fuzzy truth values.  Hence, the clause
  71.       
  72.         woof(X, Y) :- fuzzy(0.6), X > Y, f-AND.
  73.          
  74.       is incorrect since f-AND requires two operands, but only
  75.       one (from the FUZZY predicate) has been generated.      */
  76.  
  77.   f_OR :- retract(truth(X)), retract(truth(Y)), !,
  78.           fuzzy_max(X, Y, Z), fuzzy(Z), !.
  79.   
  80.   f_AND :- retract(truth(X)), retract(truth(Y)), !,
  81.            fuzzy_min(X, Y, Z), fuzzy(Z), !.
  82.   
  83.   p_OR :- retract(truth(X)), retract(truth(Y)), !,
  84.           Z = X + Y - (X * Y), fuzzy(Z), !.
  85.   
  86.   p_AND :- retract(truth(X)), retract(truth(Y)), !,
  87.            Z = X * Y, fuzzy(Z), !.
  88.   
  89.   f_NOT :- retract(truth(X)), !, Z = 1 - X, fuzzy(Z), !.
  90.  
  91.   
  92.        /*  Local predicates used by the fuzzy operators  */
  93.        
  94.        fuzzy_max(X, Y, Z) :- X >= Y, !, Z = X.
  95.        fuzzy_max(_, Y, Z) :- Z = Y.
  96.   
  97.        fuzzy_min(X, Y, Z) :- X <= Y, !, Z = X.
  98.        fuzzy_min(_, Y, Z) :- Z = Y.
  99.  
  100.